﻿using Microsoft.Data.SqlClient;
using System.Configuration;
using System.Data;


//string connectionString = ConfigurationManager.ConnectionStrings["localString"].ConnectionString;
//SqlConnection conn = new(connectionString);

//SqlCommand cmd = new("select * from product",conn);
//SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//DataTable dataTable = new DataTable();
//adapter.Fill(dataTable);
//Console.WriteLine(dataTable.Rows.Count);

// 1.获取链接字符串
string connectionString = ConfigurationManager.ConnectionStrings["localString"].ConnectionString;

// 2.建立数据库链接
using SqlConnection sqlConnection = new SqlConnection(connectionString);

// 3.建立数据库命令
using SqlCommand command = new("select * from product",sqlConnection);

// 4.建立适配器
using SqlDataAdapter adapter = new SqlDataAdapter(command);

//DataSet ds = new DataSet();
//adapter.Fill(ds);
//Console.WriteLine(ds.Tables[0].Rows.Count);
DataTable dt = new DataTable();
adapter.Fill(dt);
Console.WriteLine(dt.Rows.Count);
